package android.alliance.ads.example;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

import android.alliance.ads.AdAdapter;
import android.alliance.ads.example.helper.ProVersion;
import android.alliance.ads.interfaces.IBannerCallback;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.RelativeLayout;

/**
 * Android Alliance - Ads-Library
 *
 * Copyright (c) 2011-2014 Android Alliance
 *
 * http://www.android-alliance.org
 * http://www.droidspirit.com
 * http://www.strangeoptics.com
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use 
 * this file except in compliance with the License. You may obtain a copy of the License at  
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and 
 * limitations under the License.
 * 
 *  E-Mail: support@droidspirit.com
 */
public class MainActivity extends Activity implements OnClickListener {

	private final String demonstrateProVersion = "Click to demonstrate a pro-version\n(banner will not be displayed)";
	private final String demonstrateFreeVersion = "Click to demonstrate a free-version\n(banner will be displayed)";
	
	private AdAdapter adapter = AdAdapter.getInstance();
	private Button btAdvancedImplementation;
	private Button btSimpleImplementation;
	private Button btDemonstrateProVersion;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
	
		// Normal banners
		adapter.setAdmobKeyBanner("your_banner_key_here");
		adapter.setBanners(createBanner());
		
		// Fullscreen banners
		adapter.setAdmobKeyFullscreen("your_fullscreen_key_here");
		adapter.setBannersFullscreen(createFullscreenBanner());
		
		
		
		btSimpleImplementation = (Button) findViewById(R.id.btSimpleImplementation);
		btSimpleImplementation.setOnClickListener(this);

		btAdvancedImplementation = (Button) findViewById(R.id.btAdvancedImplementation);
		btAdvancedImplementation.setOnClickListener(this);
		
		btDemonstrateProVersion = (Button) findViewById(R.id.btDemonstrateProVersion);
		btDemonstrateProVersion.setOnClickListener(this);
		
		if(ProVersion.isProVersion()){
			btDemonstrateProVersion.setText(demonstrateFreeVersion);
		} else {
			btDemonstrateProVersion.setText(demonstrateProVersion);
		}
	}

	
	private Map<Integer, String> createBanner(){
	
		Map<Integer, String> alBanner = new HashMap<Integer, String>();
		
		alBanner.put(R.drawable.banner_malenmitben, "de.malenmitben");
		
		if(Locale.getDefault().getLanguage().equals(Locale.GERMAN.toString())){
			alBanner.put(R.drawable.banner_kindermund, "de.kindermund");
		}
		
		alBanner.put(R.drawable.banner_crimescenetracker, "de.crimescenetracker");
		alBanner.put(R.drawable.banner_idcardscanner, "de.idcardscanner");
		alBanner.put(R.drawable.banner_myinstructions, "de.myinstructions");
		
		return alBanner;
	}
	
	private Map<Integer, String> createFullscreenBanner(){
		Map<Integer, String> alBanner = new HashMap<Integer, String>();
		alBanner.put(R.drawable.fullscreenbanner_idcardscanner, "de.idcardscanner");
		alBanner.put(R.drawable.fullscreenbanner_myinstructions, "de.myinstructions");
		return alBanner;
	}


	@Override
	public void onClick(View v) {
		
		if(v == btSimpleImplementation){
			
			Intent startSimple = new Intent(this, ImplementationSimple.class);
			startActivity(startSimple);
			finish();
			
		} else if(v == btAdvancedImplementation){

			Intent startAdvanced = new Intent(this, ImplementationAdvanced.class);
			startActivity(startAdvanced);
			finish();
		} else if(v == btDemonstrateProVersion){
			
			if(ProVersion.isProVersion()){
				btDemonstrateProVersion.setText(demonstrateProVersion);
				ProVersion.setProVersion(false);
			} else {
				btDemonstrateProVersion.setText(demonstrateFreeVersion);
				ProVersion.setProVersion(true);
			}
		}
		
	}

	@Override
	public void onBackPressed() {
		finish();
	}
}
